package niumao.minecraft.uhc.commands;

import niumao.minecraft.uhc.LuckyBlockGame;
import niumao.minecraft.uhc.UHCGame;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class ForceStart implements CommandExecutor {
    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        if (sender instanceof Player) {
            Player player = (Player) sender;
            if (!player.isOp()) {
                player.sendMessage("Only Op can execute this command!");
                return true;
            }
            if (cmd.getName().equalsIgnoreCase("forcestart")) {
                if (args.length == 1) {
                    String name = args[0];
                    if (name.equalsIgnoreCase("uhc")) {
                        World world = player.getWorld();
                        if (world.getName().equalsIgnoreCase("world")) {
                            if (!UHCGame.canStart) {
                                player.sendMessage("§c游戏已经开始，禁止再次开启.");
                                return true;
                            }
                            UHCGame.start();
                            Bukkit.broadcastMessage("§c某个傻缺腐竹 §f" + player.getDisplayName() + " §c强制开启了极限生存冠军游戏.");
                            return true;
                        }
                        player.sendMessage("You can't use this command on this world!");
                        return true;
                    } else if (name.equalsIgnoreCase("luck")) {
                        LuckyBlockGame.start();
                        Bukkit.broadcastMessage("§c某个傻缺腐竹 §f" + player.getDisplayName() + " §c强制开启了幸运方块游戏.");
                        return true;
                    }
                }
                return false;
            }
        }
        sender.sendMessage(ChatColor.RED + "only Player can executor this command!");
        return true;
    }
}
